<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24" id="l_tree" :style="'height:' + ht + 'px;'">
        <el-tree
          v-loading="loadtreeing"
          default-expand-all
          :data="xzqhOptions"
          node-key="orgCd"
          :props="defaultProps"
          @node-click="handleNodeClick"
        ></el-tree>
      </el-col>
      <el-col :span="20" :xs="24" style="padding-left: 15px">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
        >
          <!-- <el-form-item>
                        <treeselect v-model="queryParams.adCode" :options="xzqhOptions" :normalizer="normalizer"
                            :show-count="true" placeholder="行政区划" />
                    </el-form-item> -->
          <!-- <el-form-item>
                        <el-select v-model="queryParams.chanLevel" placeholder="渠道等级" clearable size="small" >
                            <el-option v-for="dict in dict.type.sys_chan_level" :key="dict.value"
                                :label="dict.label" :value="dict.value" />
                        </el-select>
                    </el-form-item> -->
          <el-form-item>
            <el-select
              v-model="queryParams.runningState"
              placeholder="是否在线"
              clearable
              size="small"
            >
              <el-option key="0" label="在线" value="0" />
              <el-option key="1" label="离线" value="1" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="queryParams.statNm"
              placeholder="测站"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="queryParams.statId"
              placeholder="请选择建设属性"
              clearable
            >
              <el-option
                v-for="dict in dict.type.stat_id"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['waterManagement:WaterRegimeMonitor:export']"
              >导出</el-button
            >
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="wmList" stripe>
          <!-- <el-table-column label="测站代码" prop="stCode" width="200" /> -->
          <el-table-column
            label="序号"
            type="index"
            align="center"
            width="50"
          />
          <el-table-column label="测站名称" prop="statNm" min-width="200">
            <template slot-scope="scope">
              <span style="color: #ff0202" v-if="scope.row.eqType == 2">*</span
              ><span>{{ scope.row.statNm }}</span>
            </template>
          </el-table-column>
          <el-table-column label="时间" align="center" prop="tm" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.chkTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            style="font-weight: bold"
            label="流量（m³/s）"
            align="center"
            prop="curFlow"
            min-width="120"
          >
            <template slot-scope="scope">
              <span style="font-weight: 800">{{
                scope.row.curFlow == null ? "--" : scope.row.curFlow
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            style="font-weight: bold"
            label="累计流量（m³）"
            align="center"
            prop="sumFlow"
            min-width="120"
          >
            <template slot-scope="scope">
              <span style="font-weight: 800">{{
                scope.row.sumFlow == null ? "--" : scope.row.sumFlow
              }}</span>
            </template>
          </el-table-column>
          <el-table-column  label="电压(V)" prop="cellVolt" min-width="100"></el-table-column>
          <!--          <el-table-column label="信号强度(dBm)" prop="signalSize"   min-width="100"></el-table-column>-->
          <el-table-column
            label="状态（在线/离线）"
            align="center"
            prop="runningState"
            width="160"
          >
            <template slot-scope="scope">
              <span v-show="scope.row.runningState == 0" style="color: #2d8c34"
                >在线</span
              >
              <span v-show="scope.row.runningState == 1" style="color: #919294"
                >离线</span
              >
            </template>
          </el-table-column>
          <el-table-column
            label="信息详情"
            align="center"
            class-name="small-padding fixed-width"
            fixed="right"
          >
            <template slot-scope="scope">
              <img
                @click="sqjcinfo(scope.row)"
                style="cursor: pointer; margin-top: 6px"
                src="../../../assets/icons/sjjgicon.png"
              />
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { listsl, getxzqh } from "@/api/measurement/watermonitor";
import { organtreeList } from "@/api/common";

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Waterregime",
  components: { Treeselect },
  dicts: ["sys_chan_level", "st_eqtype", "stat_id"],
  data() {
    return {
      // 行政区划树选项
      xzqhOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      wmList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgCd: undefined,
        chanLevel: undefined,
        runningState: undefined,
        statNm: undefined,
      },
      defaultProps: {
        children: "children",
        label: "orgNm",
      },
      ht: 400,
      loadtreeing: true,
    };
  },
  created() {
    var htd = document.body.clientHeight * 0.85;
    this.ht = htd;
    this.getTreeselect();
    this.getList();
  },
  methods: {
    handleNodeClick(data) {
      if (data) {
        this.queryParams.orgCd = data.orgCd;
        this.handleQuery();
      }
    },
    cktj(zt) {
      this.queryParams.runningState = zt != "0" ? zt : undefined;
      this.getList();
    },
    sqjcinfo(irow) {
      const stcode = irow.statCd;
      this.$router.push({
        path: "/information/zxjp/slsub_qdsq",
        query: { stcode: stcode },
      });
    },
    /** 查询行政区域下拉树结构 */
    getTreeselect() {
      this.loadtreeing = true;
      organtreeList().then((response) => {
        this.xzqhOptions = this.handleTree(
          response.data,
          "orgCd",
          "parentOrgCd"
        );
        this.loadtreeing = false;
      });
    },
    /** 查询测站列表 */
    getList() {
      this.loading = true;
      listsl(this.queryParams).then((response) => {
        this.wmList = response.data.stationList.rows;
        this.total = response.data.stationList.total;
        this.loading = false;
      });
    },
    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.adCode,
        label: node.adName,
        children: node.children,
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/waterManagement/WaterRegimeMonitor/export2",
        {
          ...this.queryParams,
        },
        `水情监测_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.zj_item {
  width: 100%;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .it_zy {
    display: inline-block;
  }
  .item_top {
    cursor: pointer;
    display: inline-flex;
    width: 31%;
    min-width: 300px;
    padding: 25px 0;
    background: #f7fbfe;
    align-items: center;
    justify-content: center;
  }
  .iz_num {
    font-size: 32px;
    font-weight: 500;
  }
  .iz_wz {
    font-size: 15px;
    color: #8a8b8d;
  }
}

.el-form-item--medium .el-form-item__content {
  line-height: 30px;
}

.vue-treeselect__placeholder,
.vue-treeselect__single-value {
  line-height: 30px;
}

.vue-treeselect {
  width: 300px;
  height: 30px;
  .vue-treeselect__control {
    height: 30px;
    .el-form-item--medium .el-form-item__content {
      line-height: 30px;
      .vue-treeselect__placeholder,
      .vue-treeselect__single-value {
        line-height: 30px;
      }
    }
  }
}

#l_tree {
  padding-right: 15px;
  border-right: 1px solid #e5e5e5;
  min-height: 600px;
  overflow-x: auto;
}

#l_tree::-webkit-scrollbar {
  width: 0px; /*对垂直流动条有效*/
}
</style>
